<html xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity4">
<head th:include="include/includeTablebase"></head>
<body>

<div class="panel-body" style="padding-bottom:0px;">
    <div class="panel panel-default">
        <div class="panel-heading">查询条件</div>
        <div class="panel-body">
            <form class="form-inline" role="form" style="float: left; width: 100%;" method="post" id="queryPatrolControl">
                <div class="form-group">
                    <label for="patrolType">路径类型:</label>
                    <select  class="form-control" name="patrolType" id="patrolType" >
                        <option value="-1">请选择路径类型</option>
                    </select>
                </div>
                <div class="form-group">
                    <label for="patrolTypeName">具体路径:</label>
                    <select class="form-control" name="patrolTypeName" id="patrolTypeName" >
                        <option value = "-1">请选择</option>
                    </select>
                </div>
                <div class="form-group">
                    <button type="button" id="queryBtn" onclick="doQuery();" class="btn btn-primary">查询</button>
                </div>
            </form>
        </div>
    </div>
    <table id="t_table" style="margin-top: -50px;">
    </table>
</div>
<script th:inline="javascript">
    $(function() {
        setTimeout('initTable()',100);
        $.post("dict/getType", {type: "PATROL_TYPE"},
            function (r) {
                for (var i = 0; i < r.data.length; i++) {
                    $("#patrolType").append("<option value=" + r.data[i].value + ">" + r.data[i].value + "</option>");
                }
            });
        $.post("dict/getType", {type: "A路线"},
            function (r) {
                for (var i = 0; i < r.data.length; i++) {
                    $("#patrolTypeName").append("<option value=" + r.data[i].value + ">" + r.data[i].value + "</option>");
                }
            });
    });
    $("#patrolType").click(function () {
        var areaId =  $("#patrolType option:selected").val()
        if(areaId == '-1'){
            return;
        }
        $.post("dict/getType", {type: areaId},
            function (r) {
                $("#patrolTypeName").empty()
                $("#patrolTypeName").append("<option value= '-1'>请选择</option>");
                for (var i = 0; i < r.data.length; i++) {
                    $("#patrolTypeName").append("<option value=" + r.data[i].value + ">" + r.data[i].value + "</option>");
                }
            });
    });

    function doQuery(){
        // 移除遮罩层的属性否则会导致在移动端无法显示滚动条
        $('body').removeClass("modal-open");
        $('#t_table').bootstrapTable('refresh');    //刷新表格
    }

    function initTable(){
        $.fn.bTableUtil({
            id:"t_table",
            url:"patrolControl/list",
            formId :"queryPatrolControl",
            sortName : 'id',
            sortOrder : 'desc',
            pageSize : 5,
            toolbars:[
                {
                    text: '添加',
                    iconCls: 'glyphicon glyphicon-plus',
                    code : 'add_sys_information',
                    verify : false,// true 表示需要经过权限验证，false表示不需要经过权限验证
                    handler: function () {
                        window.Ewin.dialog({title:"添加",url:"patrolControl/addPage",gridId:"gridId",width:400,height:500})
                    }
                },
                {
                    text: '修改',
                    iconCls: 'glyphicon glyphicon-pencil',
                    code : 'edit_sys_information',
                    verify : false,// true 表示需要经过权限验证，false表示不需要经过权限验证
                    handler: function () {
                        var rows = $('#t_table').bootstrapTable('getSelections');
                        if(rows.length==0||rows.length>1){
                            window.Ewin.alert({message:'请选择一条需要修改的数据!'});
                            return false;
                        }

                        window.Ewin.dialog({title:"修改",url:"patrolControl/updatePage?id="+rows[0].id,gridId:"gridId",width:400,height:500});
                    }
                },
                {
                    text: '删除',
                    iconCls: 'glyphicon glyphicon-remove',
                    code : 'remove_sys_information',
                    verify : false,// true 表示需要经过权限验证，false表示不需要经过权限验证
                    handler: function () {
                        var rows = $('#t_table').bootstrapTable('getSelections');
                        if(rows.length==0){
                            window.Ewin.alert({message:'请选择一条需要删除的数据!'});
                            return false;
                        }
                        window.Ewin.confirm({title:'提示',message:'是否要删除您所选择的记录？',width:500}).on(function (e) {
                            if (e) {
                                $.post("patrolControl/removeBath",{json:JSON.stringify(rows)},function(e){
                                    if(e.result){
                                        window.Ewin.alert({message:e.msg});
                                        doQuery();
                                    }
                                });
                            }
                        });
                    }
                },
                {
                    text: '重新加载',
                    iconCls: 'glyphicon glyphicon-record',
                    verify : false,
                    handler: function () {
                        window.Ewin.confirm({title:'提示',message:'是否要需要重新加载数据？',width:500}).on(function (e) {
                            if (e) {
                                $.post("patrolControl/reload",function(e){
                                    if(e.result){
                                        window.Ewin.alert({message:e.msg});
                                    }
                                });
                            }
                        });
                    }
                }
            ],
            columns: [
                {
                    checkbox: true
                },
                {
                    field: '',
                    title: '序号',
                    formatter: function (value, row, index) {
                        return index+1;
                    }
                },
                {
                    field : 'patrolType',
                    title : '路线类型',
                    align : 'center',
                    valign : 'middle',
                    sortable : true
                },
                {
                    field : 'patrolTypeName',
                    title : '具体路线',
                    align : 'center',
                    valign : 'middle',
                    sortable : true
                },
                {
                    field : 'recordA',
                    title : '打卡点A',
                    align : 'center',
                    valign : 'middle',
                    sortable : true,
                    formatter: function (value, row, index) {
                        if(value != null){
                            var unixTimestamp = new Date(value);
                            return unixTimestamp.toLocaleString();
                        }else{
                            return '还未打卡';
                        }
                    }
                },
                {
                    field : 'recordB',
                    title : '打卡点B',
                    align : 'center',
                    valign : 'middle',
                    sortable : true,
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var unixTimestamp = new Date(value);
                            return unixTimestamp.toLocaleString();
                        } else {
                            return '还未打卡';
                        }
                    }
                },{
                    field : 'recordC',
                    title : '打卡点C',
                    align : 'center',
                    valign : 'middle',
                    sortable : true,
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var unixTimestamp = new Date(value);
                            return unixTimestamp.toLocaleString();
                        } else {
                            return '还未打卡';
                        }
                    }
                },
                {
                    field : 'recordD',
                    title : '打卡点D',
                    align : 'center',
                    valign : 'middle',
                    sortable : true,
                    formatter: function (value, row, index) {
                        if (value != null) {
                            var unixTimestamp = new Date(value);
                            return unixTimestamp.toLocaleString();
                        } else {
                            return '还未打卡';
                        }
                    }
                },
                {
                    field : 'createMgrName',
                    title : '创建人',
                    align : 'center',
                    valign : 'middle',
                    visible : false,
                    sortable : true
                },
                {
                    field : 'createTime',
                    title : '记录时间',
                    align : 'center',
                    valign : 'middle',
                    sortable : true,
                    formatter: function (value, row, index) {
                        var unixTimestamp = new Date(value);
                        return unixTimestamp.toLocaleString();
                    }
                }]
        });
    }
</script>
</body>
</html>